package cn.semes.user.dto;

import cn.semes.basic.util.MD5Utils;
import cn.semes.basic.util.StrUtils;
import cn.semes.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class EmailRegistrationDto {

    @NotBlank(message = "邮箱号不能为空")
    private String email;

    @NotBlank(message = "邮箱号图形验证码")
    private String imageCodeValue;
    @NotBlank(message = "邮箱验证码不能为空")
    private String smsCode;
    @NotBlank(message = "密码不能为空")
    private String password;

    @NotBlank(message = "确认密码不能为空")
    private String passwordRepeat;

    public User getUser() {
        String salt = StrUtils.getComplexRandomString(32);
        String password = MD5Utils.encrypByMd5(this.getPassword() + salt);
        return User.builder()
                .username("暂无待修改")
                .email(this.email)
                .salt(salt)
                .state(1)
                .createtime(new Date())
                .password(password)
       .build();
    }

}
